load("@rules_python//python:defs.bzl", "py_binary")
load("@pip_deps//:requirements.bzl", "requirement")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

exports_files([
    "ecies_test_public_keyset.json",
    "ecies_test_private_keyset.json",
])

py_binary(
    name = "hybrid_encrypt",
    srcs = ["hybrid_encrypt.py"],
    python_version = "PY3",
    deps = [
        requirement("absl-py"),
        "@tink_py//tink:cleartext_keyset_handle",
        "@tink_py//tink:tink_python",
        "@tink_py//tink/hybrid",
    ],
)

py_binary(
    name = "hybrid_decrypt",
    srcs = ["hybrid_decrypt.py"],
    python_version = "PY3",
    deps = [
        requirement("absl-py"),
        "@tink_py//tink:cleartext_keyset_handle",
        "@tink_py//tink:tink_python",
        "@tink_py//tink/hybrid",
    ],
)

sh_test(
    name = "hybrid_encrypt_test",
    size = "small",
    srcs = ["hybrid_encrypt_test.sh"],
    args = [
        "$(rootpath :hybrid_encrypt)",
        "$(rootpath :hybrid_decrypt)",
        "$(rootpath :ecies_test_public_keyset.json)",
        "$(rootpath :ecies_test_private_keyset.json)",
    ],
    data = [
        ":hybrid_encrypt",
        ":hybrid_decrypt",
        ":ecies_test_public_keyset.json",
        ":ecies_test_private_keyset.json",
    ],
)

# This runs the previous test assuming the Tink python package has been
# installed previously with pip3 install.
sh_test(
    name = "hybrid_encrypt_test_package",
    size = "small",
    srcs = ["hybrid_encrypt_test.sh"],
    args = [
        "'python3 $(rootpath :hybrid_encrypt)'",
        "'python3 $(rootpath :hybrid_decrypt)'",
        "$(rootpath :ecies_test_public_keyset.json)",
        "$(rootpath :ecies_test_private_keyset.json)",
    ],
    data = [
        ":hybrid_encrypt",
        ":hybrid_decrypt",
        ":ecies_test_public_keyset.json",
        ":ecies_test_private_keyset.json",
    ],
)
